package com.base.cn.platform.os.controller.mobile.agent.income;

import com.base.cn.platform.os.common.MobileBaseController;
import com.base.cn.platform.os.common.utils.ObjectUtils;
import com.base.cn.platform.os.service.course.agent.income.AgentIncomeInfoService;
import com.base.cn.platform.os.service.course.agent.user.AgentUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * 推广员收益明细Controller
 * @author LIZHIPENG
 * @create 2018-06-29 下午 4:48
 */
@Controller
@RequestMapping("/mobile/uc/agent/income")
public class MobileAgentIncomeInfoController extends MobileBaseController {

    @Autowired
    private AgentUserService agentUserService;
    @Autowired
    private AgentIncomeInfoService agentIncomeInfoService;

    /**
     * 查询推广员的收益明细列表
     * @param model Model
     * @param request HttpServletRequest
     * @param currentPage 当前页码
     * @return
     */
    @RequestMapping("/getIncomeInfoList")
    public String getIncomeInfoList(Model model, HttpServletRequest request,
                                    @RequestParam(value = "currentPage", required = false, defaultValue = "1") int currentPage,
                                    @RequestBody Map<String, Object> params){
        BigDecimal userId = webMobileLoginUtil.getLoginUserId(request);
        Map<String, Object> agentUser = agentUserService.findAgentUserByUserId(userId, false, false, false);
        Map<String, Object> dataMap = new HashMap<>();
        if(ObjectUtils.isNotEmpty(agentUser)){
            params.put("agentUserId", agentUser.get("id"));
            dataMap = agentIncomeInfoService.queryIncomeInfoListPage(currentPage, params, true, true);
        }
        model.addAttribute("dataMap", dataMap);
        return resultPage("/agent/income/agent-income-info-list");
    }
}
